package com.resou.reader.base;

import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public abstract class ResouBasePresenter<V extends BaseView> implements BasePresenter {
    private CompositeDisposable mCompositeDisposable;
    protected V mView;
    public int pageSize = 15;
    public int localNum = 0;//本地计算的总数量
    public int totalNum = 0;//远程得到的数量

    public ResouBasePresenter(V view) {
        mView = view;
        mCompositeDisposable = new CompositeDisposable();
    }

    protected void addCompositeDisposable(Disposable disposable) {
        mCompositeDisposable.add(disposable);
    }

    /**
     * 在订阅方法中初始化数据
     */
    @Override
    public void subscribe() {
        mView.initData();
    }

    protected Scheduler getIOSchedulers() {
        return Schedulers.io();
    }

    protected Scheduler getMainSchedulers() {
        return AndroidSchedulers.mainThread();
    }

//    /**
//     * 抽象此方法让presenter初始化数据
//     */
//    public abstract void initData();

    /**
     * 销毁时清除mCompositeDisposable避免内存泄漏
     */
    @Override
    public void unsubscribe() {
        mCompositeDisposable.dispose();
    }

}
